package com.gxa.day2022_07_29_21.homework.order_system_4.ui;

import com.gxa.day2022_07_29_21.homework.order_system_4.service.DishService;
import com.gxa.day2022_07_29_21.homework.order_system_4.service.OrderService;


import java.util.Scanner;

public class OrderSystem4 {
    private static OrderService orderService = new OrderService();
    private static DishService dishService = new DishService();
    static int isKeepOrder;//default不写就是default 权限本类 和 同包使用

    //
    public static Scanner scanner = new Scanner(System.in);
    static int intputVal = -1;

    public static void main(String[] args) {
        System.out.println("欢迎使用回头客订餐系统！");

        do {
            mainMenu();
                System.out.print("请选择：");
                intputVal = scanner.nextInt();
            while (intputVal<0 || intputVal>6){
                System.out.print("请输入1-6之间的选项：");
                intputVal = scanner.nextInt();
            }
            switch (intputVal) {
                case 1:
                    keepDoing("createOrder");
                    break;
                case 2:
                    orderService.getOrders();
                    returnMain();
                    break;
                case 3:
                    keepDoing("signOrder");
                    break;
                case 4:
                    keepDoing("deleteOrder");
                    break;
                case 5:
                    keepDoing("praise");
                    break;
                case 6:
                    intputVal=-1;
//                    System.exit(1);//直接结束程序
                    break;
            }
        } while (intputVal == 0);
        System.out.println("***感谢使用，欢迎下次光临!***");
    }

    /**
     * 持续做某事的方法
     *
     * @param methodName
     */
    static void keepDoing(String methodName) {
        String doWhat="";
        do{
            if("createOrder".equals(methodName)){
                doWhat = "点餐";
                orderService.createOrder();
            }else if("praise".equals(methodName)){
                doWhat = "点赞";
                dishService.praise();
            }else if("signOrder".equals(methodName)){
                doWhat = "签收订单";
                orderService.signOrder();
            }else if("deleteOrder".equals(methodName)){
                doWhat = "删除订单";
                orderService.deleteOrder();
            }
            System.out.print("输入 1 继续"+doWhat+"，输入 0 (或其他) 停止"+doWhat+":");
            isKeepOrder = scanner.nextInt();
        }while (1==isKeepOrder);
        intputVal = 0;
    }



    /**
     * 返回主菜单 方法
     */
    static void returnMain() {
        while (intputVal!= 0){
            System.out.print("输入0返回主菜单：");
            intputVal = scanner.nextInt();
        }
    }

    /**
     * 主菜单
     */
    static void mainMenu() {
        System.out.println("1.我要订餐");
        System.out.println("2.查看餐带");
        System.out.println("3.签收订单");
        System.out.println("4.删除订单");
        System.out.println("5.我要点赞");
        System.out.println("6.退出系统");
    }


}
